﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebsiteDataModel;

public partial class morning_zsadd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
            foreach (WebsiteDataModel.ZS_Title t in de.ZS_Title.ToList())
            {
                ListItem item = new ListItem();
                item.Value = t.id.ToString();
                item.Text = t.title;
                DropDownList1.Items.Add(item);
            }

            showInfo();
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        showInfo();
    }

    private void showInfo() 
    {
        int tid = int.Parse(this.DropDownList1.SelectedValue);
        WebsiteDataEntities de = new WebsiteDataEntities();
        var re = de.ZS_ContentData.Where(a => a.BelongsIndex == tid);
        this.Repeater1.DataSource = re;
        this.Repeater1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string ids = Request["zsid"];
        string names = Request["zsname"];
        string prices = Request["price"];
        string zdfs = Request["updown"];

        string[] arrid = ids.Split(new char[] { ',' });
        string[] arrname = names.Split(new char[] { ',' });
        string[] arrprice = prices.Split(new char[] { ',' });
        string[] arrzdf = zdfs.Split(new char[] { ',' });

        WebsiteDataEntities de = new WebsiteDataEntities();

        for (int i = 0; i < arrid.Length; i++) 
        {
            int id = int.Parse(arrid[i]);
            var re = de.ZS_ContentData.Where(a => a.id == id);
            if (re.Count() > 0) 
            {
                ZS_ContentData content = re.ToArray()[0];
                content.name = arrname[i];
                content.newprice = arrprice[i];
                content.ZDF = arrzdf[i];
            }
        }

        int num = de.SaveChanges();

        if (num > 0)
        {
            this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('保存成功.');</script>");
        }
        else
        {
            this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('保存失败.');</script>");
        }

        showInfo();
    }
}